﻿using RankDemo.WebApi.Entities;
using System.Collections.Concurrent;

namespace RankDemo.WebApi.Services
{
    public interface ICustomerService
    {
        List<Customer> GetAll();
        Customer? GetCustomer(long customerId);
        void CreateCustomer(Customer customer);
    }

    public class CustomerService : ICustomerService
    {
        private static readonly ConcurrentDictionary<long, Customer> _customerDictionary = new ConcurrentDictionary<long, Customer>();

        public void CreateCustomer(Customer customer)
        {
            _customerDictionary.TryAdd(customer.CustomerId, customer);
        }

        public Customer? GetCustomer(long customerId)
        {
            return _customerDictionary.GetValueOrDefault(customerId);
        }

        public List<Customer> GetAll()
        {
            return _customerDictionary.Values.ToList();
        }
    }
}
